package de.jkoslows.decisions.control;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import de.jkoslows.decisions.entity.Item;

public class Items {

	static {
		id = 0;
		items = new HashSet<Item>();
	}

	private static int id;

	private static Set<Item> items;

	public static Item create(String name, String description) {
		synchronized (items) {
			Item item = new Item(id++, name, description);
			if (items.contains(item))
				throw new IllegalStateException(
						"something went wrong items does already exist");
			items.add(item);
			return item;
		}

	}

	public static Item update(Item item) {
		synchronized (item) {
			items.add(item);
			return item;
		}
	}

	public static Collection<Item> getItems() {
		synchronized (items) {
			return new HashSet<Item>(items);
		}

	}

	public static void delete(Item item) {
		synchronized (item) {
			items.remove(item);
		}
	}

}
